#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int, int> PII;
vector<PII> a;
int n;

vector<PII> merge(vector<PII> &a)
{
    sort(a.begin(), a.end());
    vector<PII> ans;
    for (int i = 0; i < a.size(); ++i)
    {
        int st = a[i].first, ed = a[i].second;
        while (i + 1 != a.size() && a[i + 1].first <= ed)
            ed = max(ed, a[++i].second);
        ans.push_back({st, ed});
    }
    return ans;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        a.push_back({l, r});
    }
    printf("%d", merge(a).size());
    return 0;
}